import React from 'react'
import { withRouter } from 'react-router-dom'
import { connect } from 'dva'

import * as Constant from '../../constant'

import './style.css'

const OrderSearch = ({ history, order }) => {

    const toOrderList = () => {
        history.push('/orderList')
    }
    let payNum = 0
    let createAtNum = 0
    for (let item of order.list) {
        if (item.status === Constant.ORDER_STATUS.ORDER_STATUS_CREATEAT) {
            createAtNum++
        }
        if (item.status === Constant.ORDER_STATUS.ORDER_STATUS_PAY) {
            payNum++
        }
    }

    return (
        <div className='orderSearch'>
            <div onClick={toOrderList}  >
                <i className='iconfont icon-bijiben' />
                <span>全部订单</span>
            </div>
            <div onClick={toOrderList} >
                <i className='iconfont icon-weibiaoti-' />
                <span>待付款</span>
                {createAtNum !== 0 && <b className='num'>{createAtNum}</b>}
            </div>
            <div onClick={toOrderList} >
                <i className='iconfont icon-che' />
                <span>待收货</span>
                {payNum !== 0 && <b className='num'>{payNum}</b>}
            </div>
            <div onClick={toOrderList} >
                <i className='iconfont icon-qian' />
                <span>已完成</span>
            </div>
        </div>
    )
}

const mapState = state => ({
    order: state.order
})

export default connect(mapState)(withRouter(OrderSearch))

